﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SL.WorkfowDesigner.ViewModels;

namespace SL.WorkfowDesigner
{
    public partial class SilverlightControl1 : UserControl
    {
                private static int ZIndex_GridLine = 1;
        private bool _initializeComponentFinished = false;
        public static List<LayoutTransformer> transformers = new List<LayoutTransformer>();
        public SilverlightControl1()
        {            
            InitializeComponent();
            _initializeComponentFinished = true;
            this.DataContext = new MainLayoutViewModel();
 
        }

        public MainLayoutViewModel DataContextEntity
        {
            get { return this.DataContext as MainLayoutViewModel; }
        }

 

        private void btnReset_OnClick(object sender, RoutedEventArgs e)
        {
            this.DataContextEntity.ZoomLevelValue = 100;
        }

        private void MainPage_OnLoaded(object sender, RoutedEventArgs e)
        {

            //MessageBox.Show(this.FreeLayout.RowDefinitions[5].ActualHeight.ToString());
            //MessageBox.Show(this.FreeLayout.RowDefinitions[5].Height.ToString());
            //MessageBox.Show(this.FreeLayout.ColumnDefinitions[5].ActualWidth.ToString());
            //MessageBox.Show(this.FreeLayout.ColumnDefinitions[5].Width.ToString());
        }

        private void btnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            var r = new Rectangle();
            r.Fill = new SolidColorBrush(Color.FromArgb(255,50,60,210));
 
            r.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            r.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;


 
        }

        private void Panel_Loaded(object sender, RoutedEventArgs e)
        {
            StackPanel grid = sender as StackPanel;
            grid.Width = accordion1.ActualWidth - 5;
        }

        private void btnLarge_OnClick(object sender, RoutedEventArgs e)
        {
 
        }


        private void silderZoom_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (_initializeComponentFinished)
            {
 
                scaleTransform.ScaleX = silderZoom.Value / 100d;
                scaleTransform.ScaleY = silderZoom.Value / 100d;
                layoutTransform.ApplyLayoutTransform();
                
                //FreeLayoutScrollViewer.ScrollToVerticalOffset(FreeLayoutScrollViewer.Height * scaleTransform.ScaleX);
                //FreeLayoutScrollViewer.ScrollToHorizontalOffset(FreeLayoutScrollViewer.Width * scaleTransform.ScaleY);
                //FreeLayoutScrollViewer.UpdateLayout();
            }

        }

        private void LayoutRoot_LayoutUpdated(object sender, EventArgs e)
        {
            MessageBox.Show(LayoutRoot.ActualHeight.ToString());
            MessageBox.Show(LayoutRoot.ActualWidth.ToString());

        }
    }
}
